home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / The World of Computer Software.iso / pctv3n2.zip / TOSHIBA.PAS < prev    next >
Pascal/Delphi Source File  |  1992-03-31  |  3KB  |  110 lines

  1. PROGRAM toshiba;
  2.  
  3. { Power supply control functions on Toshiba T1000SE. }
  4. { Largely the same on other Toshiba laptops. }
  5.  
  6. PROCEDURE ps_command(b: byte);
  7.   { Sends a command to the Toshiba power supply }
  8. VAR r: byte;
  9.     i: integer;
  10. BEGIN
  11.   port[$0e8] := $5a;                            { Send the key }
  12.   port[$0e9] := b;                          { Send the command }
  13.   i := 0;
  14.   REPEAT
  15.     i := i + 1;
  16.     r := port[$0e9]
  17.   UNTIL ((r AND $40) <> 0) OR (i > 30000);
  18.                                      { Wait until cmd accepted }
  19.   IF i>30000 THEN
  20.     write('<WARNING: Command timed out>')
  21.   ELSE
  22.     r := port[$0e8]               { Accept the acknowledgement }
  23. END;
  24.  
  25. FUNCTION ps_response: byte;
  26.   { Obtains data sent by power supply to CPU }
  27. VAR r: byte;
  28.     i: integer;
  29. BEGIN
  30.   i := 0;
  31.   REPEAT
  32.     i := i + 1;
  33.     r := port[$0e9]
  34.   UNTIL ((r AND $40) <> 0) OR (i > 30000);
  35.                                        { Wait until data ready }
  36.   IF i>30000 THEN
  37.     BEGIN
  38.       write('<WARNING: Data timed out>');
  39.       ps_response := port[$0e8]
  40.     END
  41.   ELSE
  42.     BEGIN
  43.       ps_response := port[$0e8];            { Get the response }
  44.       port[$0e8] := $5a;              { Unlock the output port }
  45.       port[$0e9] := $ff;         { Send acknowledgement signal }
  46.     END
  47. END;
  48.  
  49. FUNCTION battery_level: byte;
  50.   { Range 0 to 7.  If user has not set it, then set it to 7. }
  51.   { That's reasonable, because if weak, the battery will }
  52.   { almost immediately drop to a lower level. }
  53. VAR r: byte;
  54. BEGIN
  55.   ps_command($c0);
  56.   r := ps_response AND $0f;
  57.   IF r < 8 THEN
  58.     BEGIN
  59.       ps_command($d7);  { set to level 7 }
  60.       ps_command($c0);  { inquire again }
  61.       r := ps_response;
  62.     END;
  63.   battery_level := r AND $07
  64. END;
  65.  
  66. PROCEDURE set_battery_level(b:byte);
  67.   { Sets the battery level. Range is 0 to 7. }
  68. BEGIN
  69.   ps_command($d0 + (b AND $07))
  70. END;
  71.  
  72. PROCEDURE screen_off;
  73.   { Turns fluorescent screen off if battery powered. }
  74.   { If using AC power, screen stays on. }
  75. BEGIN
  76.   ps_command($b0)
  77. END;
  78.  
  79. PROCEDURE screen_on;
  80.   { Turns fluorescent screen on. }
  81. BEGIN
  82.   ps_command($bf)
  83. END;
  84.  
  85.  
  86. BEGIN  { Demonstration of the above }
  87.   writeln('TOSHIBA CONTROL DEMONSTRATION');
  88.   writeln('Switching screen illumination off (if battery powered).');
  89.   writeln('Press Enter when ready, the Enter again...');
  90.   readln;
  91.  
  92.   screen_off;
  93.   readln;
  94.  
  95.   screen_on;
  96.  
  97.   writeln('Current battery level is ',battery_level);
  98.   writeln('Press Enter...');
  99.   readln;
  100.  
  101.   writeln('Setting battery level to 7...');
  102.   set_battery_level(7);
  103.  
  104.   writeln('Current battery level is ',battery_level);
  105.   writeln('Press Enter...');
  106.   readln;
  107.  
  108.   writeln('That''s all, folks!')
  109. END.
  110.